const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        tab:[
            {
              id: 1,
              title: '车型',
            
            },
            {
                id: 2,
                title: '车辆',
              
              },
              {
                id: 3,
                title: '方案',
              
              },
          
          ],
          selectedTab: 0,
 
    translateX: 0,
    type:1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that  = this;
        var deviceInfo = wx.getDeviceInfo();
          console.log(deviceInfo)
          let d = app.globalData;
          var open=wx.getStorageSync('open');  
          this.setData({
              //id:id,
              open:open,
              width:d.windowWidth,
              height:d.windowHeight,
              statusBarHeight:d.statusBarHeight,
              navHeight:d.navHeight,
              marginTop:d.navTitleTop,
              bottom:d.bottom,
              domain:d.domain,
              imgUrl:d.imgUrl,
              platform:deviceInfo.platform
          })
    },
    goBack:function(){
        wx.navigateBack();
    },
    goto(e){
        console.log(e);
        var url=e.currentTarget.dataset.url;
        console.log(url);
        var index=e.currentTarget.dataset.index;
        app.goto(url,index)
      // console.log(url);
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getIndex(1);
    },
    getIndex:function(type){
        let that = this;    
        console.log('coupon----getIndex')  
        var store_id = wx.getStorageSync('store_id');
        var open = wx.getStorageSync('open');
        wx.request({
          url: app.globalData.domain+'/wechat/index/getFavor',
          data:{from:1,user_id:open.user_id,open_id:open.id,type:type},
          success:res=>{
              console.log(res)
              var d=res.data;
           
            that.setData({
            servicePhone:d.servicePhone,
            list:d.list,
            count:d.count
         

            })
          }
      })

    },
    onTapTab(evt) {
        let d = this.data;
       const { index } = evt.currentTarget.dataset || {};
       console.log(index);
       var tab = d.tab;
       var width = ((d.width-48)/3)*index;
       console.log(tab);
       var tabs = tab[index];
       console.log(tabs)
       var now = tabs.id;
       var type  = d.type;
       console.log(now+' '+ type);
       if(type != now){
           this.getIndex(now);
       }
       this.setData({
           type:now,
         translateX:width,  
         selectedTab: index,
       })
     },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})